package ACWing.SearchAndGraphTheory.DFS;
//24.机器人的运动范围

import java.util.Scanner;

/**
 * @author :chenjie
 * @date :Created 2022/12/17 15:55
 */
public class TheRangeOFMotionOFTheRobot {
    static int k;
    static int m;
    static int n;
    static boolean[][]arr=new boolean[50][50];
    static int count=0;
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
         k=sc.nextInt();
         m=sc.nextInt();
         n=sc.nextInt();
        System.out.println(movingCount(k,m,n));
    }
    public static int movingCount(int threshold, int rows, int cols){
        if(threshold==0){//特判
            return 1;
        }
       int sum=dfs(threshold,0,0);
       return sum;
    }
    public static int dfs(int threshold,int x,int y){
        int[]dx={-1,0,1,0};
        int[]dy={0,1,0,-1};
 //       int sum=1;
        for (int i = 0; i < 4; i++) {
            int a=x+dx[i],b=y+dy[i];
            if(a<m&&a>=0&&b<n&&b>=0&&panduan(threshold,a,b)&&!arr[a][b]){
                arr[a][b]=true;
                count++;
//                sum+=dfs(threshold,a,b);
                dfs(threshold,a,b);
            }
        }
        return count;
    }
    public static boolean panduan(int threshold, int rows, int cols){
        int sum=0;
        while (rows!=0){
            sum=sum+rows%10;
            rows=rows/10;
        }
        while (cols!=0){
            sum=sum+cols%10;
            cols=cols/10;
        }

        if(sum<=threshold){
            return true;
        }
        return false;
    }
}
